import Login from '@/pages/Login/index.vue';

export default [
    {
        path: '/',
        redirect: "/login",
        //路由元信息
        meta: { show: false }
    },
    {
        path: '/login',
        component: Login,
        meta: { show: false }
    },
    {
        path: '/register',
        component: () => import('@/pages/Register/index.vue'),
        meta: { show: false }
    },
    {
        path: '/search/:keyword?',//?就是指定参数可传可不传 这样才不会引起地址出错
        component: () => import('@/pages/Search/index.vue'),
        meta: { show: true },
        name: 'Search'//params需要设置name
    },
    {
        path: '/home',
        component: () => import('@/pages/Home/index.vue'),
        meta: { show: true }
    },
    {
        path: '/detail/:skuid',
        component: () => import('@/pages/Detail/index.vue'),
        meta: { show: true }
    },
    {
        path: '/addCartSuccess',
        name: "AddCartSuccess",
        component: () => import('@/pages/AddCartSuccess/index.vue'),
        meta: { show: true }
    },
    {
        path: '/shopCart',
        name: 'ShopCart',
        component: () => import('@/pages/ShopCart/index.vue'),
        meta: { show: true }
    },
    {
        path: '/trade',
        name: 'Trade',
        component: () => import('@/pages/Trade/index.vue'),
        meta: { show: true },
        //路由独享守卫
        /* 只能从购物车界面, 才能跳转到交易界面 */
        beforeEnter(to, from, next) {
            if (from.path === '/shopCart') {
                next()
            } else {
                next('/shopCart')
            }
        }
    },
    {
        path: '/pay',
        name: 'Pay',
        component: () => import('@/pages/Pay/index.vue'),
        meta: { show: true },
        beforeEnter (to, from, next) {
            if (from.path==='/trade') {
              next()
            } else {
              next('/trade')
            }
          }
    },
    {
        path: '/paysuccess',
        name: 'Paysuccess',
        component: () => import('@/pages/PaySuccess/index.vue'),
        meta: { show: true }
    },
    {
        path: '/center',
        component: () => import('@/pages/Center/index.vue'),
        meta: { show: true },
        children: [
            {
                path: 'myorder',
                component: () => import('@/pages/Center/myOrder/index.vue'),
            },
            {
                path: 'grouporder',
                component: () => import('@/pages/Center/groupOrder/index.vue'),
            },
            {
                path: '/center',
                redirect: '/center/myorder',
            }
        ]
    },
]